print("Hello World!")

# 强制类型转换
num_str = str(8 + 3)
# 这里的','会输出一个空格
print(type(num_str), num_str)

num = 3
num **= 2  # 3**2 是3的2次方的意思
print(num)

num //= 2  # 9//2 取整除法（小数部分直接删去，没有四舍五入）

# 使用''来定义有""的字符串
name = '"张三"'
print(name)

# 使用""来定义有''的字符串
name = "'张三一'"
print(name)
name = """张三二"""
print(name)

# 使用转义字符\
name = "\"张三"
print(name)

# 字符串拼接
sing = "唱"
dance = "跳"
rap = "rap"
name = "cxk"

# 这种只能拼接字符串
introduce = "我的名字是" + name + ", 喜欢" + sing + dance + rap + "篮球"
print(introduce)

# 字符串格式化
year = 2.5
introduce = "练习时长 = %.1f年" % year
print(introduce)

num = 9
py = "Python"
talk = "%s有%d分,甚至%d分高效" % (py, num + 1, num)
print(talk)

# 字符串精度控制
"""
%m.nf
m 控制宽度，默认右对齐 小数点算一个位置
n 控制有效小数 会进行四舍五入
"""
pi = 3.141592
talk = "圆周率大概_=_%8.4f吧" % pi
print(talk)
talk = "圆周率大概_=_%-8.4f吧" % pi
print(talk)

"""
字符串快速格式化写法： f"内容{变量}"
这种写法不会进行精度控制 原样输出 不会补充0
f: format 格式化
"""
print(f"{py}有{num + 1}分，甚至{num}分高效")

# input()接收的都是字符串类型 ()内可填入提示信息
"""
user_name = input("请输入用户名")
user_type = input("请输入用户类型")
print(f"您好：%s， 您是尊贵的：%s用户，欢迎您的光临" % (user_name, user_type))
print(f"您好：{user_name}， 您是尊贵的：{user_type}用户，欢迎您的光临")
"""

# bool类型包括 True False (首字母大写)

# Python if 通过缩进判断归属

age = 10
print("我现在是%d岁" % age)
if age >= 18:
    print("我已经成年了")
    print("即将步入大学生活")
else:
    print(f"已经过了{age}年了啊")
print("时间过的真快啊")

age = 20
print("我现在是%d岁" % age)
if age >= 18:
    print("我已经成年了")
    print("即将步入大学生活")
else:
    print(f"已经过了{age}年了啊")
print("时间过的真快啊")

# while 循环语句
i = 1
Sum = 0
while i <= 100:
    Sum += i
    i += 1
print("1~100的和为%d" % Sum)

"""
# 生成随机数
# 报警告是因为import最好写在文件最上面
import random
num = random.randint(1, 100)
times = 0
while True:
    times += 1
    guess = int(input("请输入你要猜的数字："))
    if guess == num:
        print("恭喜你猜中了")
        print(f"总猜测次数为{times}")
        break
    elif guess > num:
        print("猜测的数字有点大哦，再试试吧")
    else:
        print("猜测的数字有点小哦，再试试吧")
"""

# print不输出换行
print("Hello", end='')
print("World", end='!!')
print("end")
print("next")

# \t对齐
print("hello\trrrrrrrrrrrrr")
print("nextfff\tjjj")

# while实现九九乘法表
i = 1
while i <= 9:
    j = 1
    while j <= i:
        print(f"{j} * {i} = %2d\t" % (i*j), end=' ')
        j += 1
    print()
    i += 1

# for循环语法
name = "Li Hua"
for c in name:
    print(c)

cnt = 0
name = "itheima is a brand of itcast"
for c in name:
    if c == 'a':
        cnt += 1
print(f"cnt = {cnt}", end='')

print()

# range 序列语法
for i in range(4):  # 从0开始 不包含括号里的数字
    print(i, end=' ')
print()
for i in range(1, 5):
    print(i, end=' ')
print()

# 第三个参数是步长
for i in range(1, 11, 2):
    print(i, end=' ')


# for循环没有break时会执行后面的else语句
for i in range(1, 11):
    print(i, end=' ')
else:
    print('no break')

for i in range(1, 11):
    if i == 5:
        print(f"break at {i}")
        break
    print(i, end=' ')
else:
    print("no break")


"""
r = int(input("请输入右边界："))
cnt = 0
for i in range(1, r):
    if i % 2:
        pass
    else:
        cnt += 1
print(f"偶数一共有{cnt}个", end='')
"""

# 发工资案例
"""
import random
total = 10000
while total > 0:
    for i in range(1, 21):
        ran = random.randint(1, 10)
        if ran < 5:
            print(f"员工{i},绩效分{ran},低于5分,不发工资,下一位")
        else:
            total -= 1000
            print(f"向员工{i}发放工资1000,账户余额还剩余{total}元")
print("工资发放完了,下个月领取吧")
"""
